<template>
  <el-container class="layout-container">
    <!-- 侧边栏 -->
    <el-aside width="220px" class="aside-menu">
      <div class="logo">人力资源管理系统</div>
      <el-menu
        :router="true"
        :default-active="$route.path"
        class="el-menu-vertical"
        background-color="#222"
        text-color="#fff"
        active-text-color="#409EFF"
        unique-opened>
        <el-menu-item index="/dashboard">
          <i class="el-icon-data-analysis"></i>
          <span>仪表盘</span>
        </el-menu-item>
        <el-menu-item index="/employee">
          <i class="el-icon-user"></i>
          <span>人员管理</span>
        </el-menu-item>
        <el-menu-item index="/department">
          <i class="el-icon-office-building"></i>
          <span>部门管理</span>
        </el-menu-item>
        <el-menu-item index="/position">
          <i class="el-icon-suitcase"></i>
          <span>职位管理</span>
        </el-menu-item>
        <el-menu-item index="/salary">
          <i class="el-icon-money"></i>
          <span>工资管理</span>
        </el-menu-item>
        <el-menu-item index="/business-trip">
          <i class="el-icon-location"></i>
          <span>出差管理</span>
        </el-menu-item>
        <el-menu-item index="/announcement">
          <i class="el-icon-bell"></i>
          <span>公告管理</span>
        </el-menu-item>
      </el-menu>
    </el-aside>

    <el-container>
      <!-- 顶部栏 -->
      <el-header class="header-bar">
        <div class="header-left"></div>
        <div class="header-right">
          <el-dropdown @command="handleCommand">
            <span class="user-info">
              <img class="avatar" src="../assets/img2.jpg" />
              <span class="username">admin</span>
              <i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>

      <!-- 主体内容 -->
      <el-main class="main-bg">
        <div class="main-card">
          <router-view></router-view>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: 'Layout',
  methods: {
    handleCommand(command) {
      if (command === 'logout') {
        this.$store.dispatch('user/logout')
        this.$router.push('/login')
      }
    }
  }
}
</script>

<style scoped>
.layout-container {
  height: 100vh;
}

.aside-menu {
  background: #222;
  min-height: 100vh;
  box-shadow: 2px 0 8px 0 rgba(0,0,0,0.04);
}
.logo {
  color: #fff;
  font-size: 20px;
  font-weight: bold;
  text-align: center;
  padding: 32px 0 24px 0;
  letter-spacing: 2px;
}
.el-menu-vertical {
  border-right: none;
  background: #222;
  min-height: calc(100vh - 80px);
}

.header-bar {
  background: #111;
  color: #fff;
  height: 56px;
  line-height: 56px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  border-bottom: 1px solid #222;
}
.header-left {
  flex: 1;
}
.header-right {
  margin-right: 40px;
}
.user-info {
  display: flex;
  align-items: center;
  cursor: pointer;
  color: #fff;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin-right: 10px;
  border: 2px solid #fff;
}
.username {
  margin-right: 6px;
  font-weight: 500;
}

.main-bg {
  background: #f5f6fa;
  min-height: calc(100vh - 56px);
  padding: 32px 0;
}
.main-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px 0 rgba(0,0,0,0.04);
  padding: 24px;
  min-height: 600px;
  max-width: 1200px;
  margin: 0 auto;
}
</style> 